use std::sync::Mutex;
use rbatis::object_id::ObjectId;
use rbatis::rbdc::{DateTime, Error};
use serde::Serialize;
use crate::domain::tables::SysTrash;

#[derive(Debug)]
pub struct sys_trash_service {
    pub recycle_data: Mutex<DateTime>,
}

impl sys_trash_service {
    pub fn new() -> Self {
        Self {
            recycle_data: Mutex::new(DateTime::now()),
        }
    }
    pub async fn add<T>(&self, table_name: &str, args: &[T]) -> Result<u64, Error>
        where
            T: Serialize, {
        if args.is_empty() {
            return Ok(0);
        }
        let now = DateTime::now();
        let mut trashes = Vec::with_capacity(args.len());
        for x in args {
            trashes.push(SysTrash {
                id: Some(ObjectId::new().to_string().into()),
                table_name: Some(table_name.to_string()),
                data: Some(serde_json::to_string(x).unwrap_or_default()),
                create_date: Some(now.clone()),
            });
        }
        let r=SysTrash::insert
    }
}